﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace Bmz.Laboratory.JQueryEffects.HelpClass
{
    public class JsonNetResult:JsonResult
    {
        /// <summary>
        /// 重写Mvc的JsonResult Json 序列化
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            var response = context.HttpContext.Response;
            response.ContentType = !String.IsNullOrEmpty(ContentType)?ContentType: "application/json";
            if (ContentEncoding != null)
                response.ContentEncoding = ContentEncoding;
            // If you need special handling, you can call another form of SerializeObject below
            JsonSerializerSettings settings=new JsonSerializerSettings();
            settings.ReferenceLoopHandling=ReferenceLoopHandling.Ignore;
            var serializedObject = JsonConvert.SerializeObject(Data, settings);
            response.Write(serializedObject);
        }
    }
}